package com.hnhegui.backend.merchant.controller;

import com.hnhegui.backend.entity.PageResult;
import com.hnhegui.backend.entity.Result;
import com.hnhegui.backend.merchant.api.ProductRestApi;
import com.hnhegui.backend.merchant.dto.request.DeductStockRequestDTO;
import com.hnhegui.backend.merchant.dto.request.FreezeStockRequestDTO;
import com.hnhegui.backend.merchant.dto.request.ProductPageRequestDTO;
import com.hnhegui.backend.merchant.dto.request.UnfreezeStockRequestDTO;
import com.hnhegui.backend.merchant.dto.response.ProductDetailsResponseDTO;
import com.hnhegui.backend.merchant.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/products")
public class ProductController implements ProductRestApi {

    @Autowired
    private ProductService productService;

    @Override
    public Result<PageResult<ProductDetailsResponseDTO>> getProductList(ProductPageRequestDTO request) {
        PageResult<ProductDetailsResponseDTO> result = productService.getProductList(request);
        return Result.success(result);
    }

    @Override
    public Result<ProductDetailsResponseDTO> getProductDetail(Long productId) {
        ProductDetailsResponseDTO response = productService.getProductDetail(productId);
        return Result.success(response);
    }

    @Override
    public Result<Boolean> freezeStock(FreezeStockRequestDTO request) {
        return Result.success(productService.freezeStock(request));
    }

    @Override
    public Result<Boolean> unfreezeStock(UnfreezeStockRequestDTO request) {
        productService.unfreezeStock(request);
        return Result.success(Boolean.TRUE);
    }

    @Override
    public Result<Boolean> deductStock(DeductStockRequestDTO request) {
        productService.deductStock(request);
        return Result.success(Boolean.TRUE);
    }
}
